# 开机之后执行
#!/system/bin/sh
# 不要假设您的模块将位于何处。
# 如果您需要知道此防跳和模块的放置位置，请使用$MODDIR
# 这将确保您的模块仍能正常工作
# 即使Magisk将来更改其挂载点
export USER=root
export HOME=/root
export TERM=linux
export system=/data/alpine
#[[ `ls /data/data` ]] || su

TYLJ="https://189.ly93.cc/aa2iYfyMRFNb/31340114820354170?accessToken=FDE7C87A2949966E1F6CD750AABFA0AE"
[[ `curl -s $TYLJ|grep 解析分享信息` ]] && echo 链接过期，联系楼主 && exit
if [ -r /data/alpine/busybox ];then
echo "已解压"
else
cd /sdcard && [ -r alpine.tar.gz ] || wget -O alpine.tar.gz --no-check-certificate $TYLJ 

cd /sdcard && [ -r alpine.tar.gz ] && tar -xf alpine.tar.gz -C /data && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /data/alpine/etc/apk/repositories

fi

mount_status()
{
  mount_var="$1"
  if grep -q " ${mount_var%/} " /proc/mounts; then
    return 0
  else
    return 1
  fi
}

mountdir()
{
  for mount_dir in / /dev /proc /sys /dev/shm /dev/pts /tmp;
  do
    if ! mount_status "$system${mount_dir}"; then
      case ${mount_dir} in
        /)
          mount --rbind $system $system/
          mount -o remount,exec,suid,dev "$system"
        ;;
        /dev)
          [ -d "$system/dev" ] || mkdir -p "$system/dev"
          mount -o bind /dev "$system/dev"
        ;;
        /proc)
          [ -d "$system/proc" ] || mkdir -p "$system/proc"
          mount -t proc proc "$system/proc"
        ;;
        /sys)
          [ -d "$system/sys" ] || mkdir -p "$system/sys"
          mount -t sysfs sys "$system/sys"
        ;;
        /dev/shm)
          [ -d "/dev/shm" ] || mkdir -p /dev/shm
          mount -o rw,nosuid,nodev,mode=1777 -t tmpfs tmpfs /dev/shm
          [ -d "$system/dev/shm" ] || mkdir -p $system/dev/shm
          mount -o bind /dev/shm "$system/dev/shm"
        ;;
        /dev/pts)
          [ -d "/dev/pts" ] || mkdir -p /dev/pts
          mount -o rw,nosuid,noexec,gid=5,mode=620,ptmxmode=000 -t devpts devpts /dev/pts
          [ -d "$system/dev/pts" ] || mkdir -p $system/dev/pts
          mount -o bind /dev/pts "$system/dev/pts"
        ;;
        /tmp)
          [ -d "$system/tmp" ] || mkdir -p "$system/tmp"
          mount -t tmpfs tmpfs "$system/tmp"
        ;;
      esac
    fi
  done
}

exvar()
{
  for ex_var in /dev/fd /dev/stdin /dev/stout /dev/sterr /dev/tty0 /dev/net/tun;
  do
    if [ ! -e ${ex_var} ] && [ ! -h ${ex_var} ]; then
      case ${ex_var} in
      /dev/fd)
        ln -s /proc/self/fd ${ex_var} >/dev/null 2>&1
      ;;
      /dev/stdin)
        ln -s /proc/self/fd/0 ${ex_var} >/dev/null 2>&1
      ;;
      /dev/stdout)
        ln -s /proc/self/fd/1 ${ex_var} >/dev/null 2>&1
      ;;
      /dev/stderr)
        ln -s /proc/self/fd/2 ${ex_var} >/dev/null 2>&1
      ;;
      /dev/tty0)
        ln -s /dev/null ${ex_var} >/dev/null 2>&1
      ;;
      /dev/net/tun)
        [ -d "/dev/net" ] || mkdir -p /dev/net
        mknod /dev/net/tun c 10 200
      ;;
      esac
    fi
  done
}

[ -r /data/alpine/busybox ] && rm -rf /data/alpine/busybox

cd /sdcard && [ -r busybox ] || wget -O bosybox https://ghproxy.com/https://raw.githubusercontent.com/Hnsyx/biji/main/busybox
[ -r /data/alpine/busybox ] || cp busybox /data/alpine && chmod 755 /data/alpine/busybox
[ -e /data/adb/service.d ] && [ -r /data/alpine/service.sh ] || curl -o /data/alpine/service.sh https://gitee.com/ewf-9/BiJi/raw/master/service.sh
#[ -e /data/adb/service.d ] && curl -o /data/alpine/zq.sh https://gitee.com/ewf-9/BiJi/raw/master/service.sh
[ -e /data/adb/service.d ] && echo 'sleep 20 && /data/user/0/bin.mt.plus/files/term/usr/bin/sudo sh /data/alpine/service.sh' >/data/adb/service.d/zq.sh && chmod -R 777 /data/adb/service.d/zq.sh

/data/alpine/busybox sysctl -w net.ipv4.ip_forward=1 >/dev/null 2>&1
mountdir && exvar
echo 'OK SSH: 127.0.0.1:22 passwd: 123456'
$(/data/alpine/busybox chroot $system /boot/init.sh >/dev/null 2>&1) &